package com.zhuyuan.security.handler;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.zhuyuan.core.enums.ResultCodeEnum;
import com.zhuyuan.core.util.Result;
import com.zhuyuan.core.util.ServletUtils;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @description: 自定义客户端验证异常拦截
 * @author: 张琳凯
 * @date: 2025/1/19 18:54
 **/
@Component
public class CustomAuthenticationEntryPoint extends OAuth2AuthenticationEntryPoint {

    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException)
            throws IOException {
        ServletUtils.renderString(response,ResultCodeEnum.INVALID_TOKEN);
    }
}
